<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center means_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub means_fd0_0'>
					<view class='flex flex-wrap align-center means_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
						data-url="1">
						<text class='fu-iconfont2  means_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<text class='means_fd0_0_c1'>个人资料</text>
					<view class='flex flex-wrap align-center means_fd0_0_c0'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---我的资料flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout means_flex_1">
				<view class='flex flex-wrap align-center justify-between means_fd1_0'>
					<text class='means_fd1_0_c0'>头像</text>
					<view class="upload position-relative">
						<image class=" means_fd1_0_c1_image" mode="aspectFit"
							@tap="croppingUploadImage('store_logo','avatar',userData,userData)"
							:src="userData.avatar ? userData.avatar : STATIC_URL+'37.png'"></image>
					</view>
				</view>
				<view class='flex flex-wrap align-center justify-between means_fd1_0'>
					<text class='means_fd1_0_c0'>ID</text>
					<text class='means_fd1_1_c1'>{{userData.id}}</text>
				</view>
				<view class='flex flex-wrap align-center means_fd1_0'>
					<text class='means_fd1_0_c0'>昵称</text>
					<benben-input class='flex-sub means_fd1_2_c1' type="text" :placeholder="`请输入昵称`" confirm-type="done"
						:maxlength="6" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"
						v-model="userData.nickname" />
				</view>
				<view class='flex flex-wrap align-center means_fd1_0' @tap.stop="pickerDiy1677297349960=true">
					<text class='means_fd1_0_c0'>所在地</text>
					<benben-input class='flex-sub means_fd1_3_c1' type="text" :placeholder="`请选择所在地`"
						confirm-type="done" :maxlength="-1" :disabled='true'
						placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx" v-model="userData.suozaidi" />
				</view>
				<view class='flex flex-wrap align-center justify-between means_fd1_4'>
					<text class='means_fd1_0_c0'>手机号</text>
					<text class='means_fd1_1_c1'>{{userData._mobile}}</text>
				</view>
			</view>

			<!---我的资料flex布局结束-->
			<view class="flex flex-wrap align-start justify-center benben-position-layout flex means_flex_2">
				<button class='means_fd2_0' @tap.stop="postUserDataFunc()">保存</button>

			</view>
			<view :style="{height: '128rpx'}"></view>
			<!--地址选择器开始 -->
			<benben-picker ref="benbenWritePickerCodepicker3" :visible.sync="pickerDiy1677297349960"
				:label.sync='userData.suozaidi' mode='region' :mask-show='true' :picker-height='88' :hide-area='false'>
				<template #picker-header>
					<view class='flex flex-wrap align-center justify-between means_picker3_0'>
						<text class='means_picker3_0_c0' @tap="$refs.benbenWritePickerCodepicker3.cancel()">取消</text>
						<text class='means_picker3_0_c1'>请选择地址</text>
						<text class='means_picker3_0_c2'
							@tap="$refs.benbenWritePickerCodepicker3.pickerConfirm()">确定</text>
					</view>
				</template>
			</benben-picker>
			<!--地址选择器结束 -->


		</view>
	</view>
</template>
<script>
	import UploadImage from '@/common/utils/upload-image.js'
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {},


		data() {
			return {
				"pickerDiy1677297349960": false,
				"addressLable": "",
				"userData": {
					"invite_code": "",
					"address": "",
					"address_code": "",
					"hobby": "",
					"tags": "",
					"id": "",
					"userlevel_id": "",
					"mobile": "",
					"real_name": "",
					"nickname": "",
					"avatar": "",
					"account": "",
					"email": "",
					"birthday": "",
					"gender": "",
					"create_time": "",
					"user_money": "",
					"freeze_money": "",
					"total_consumption_money": "",
					"score": "",
					"_mobile": "",
					"coupon": "",
					"collection_count": "",
					"browse_count": "",
					"total_money": "",
					"certified": "",
					"is_pay_password": "",
					"fuwuxingji": "",
					"gongzuozhuangtai": "",
					"shuzi": "",
					"jifen": "",
					"yajin": "",
					"level": {
						"aid": "",
						"name": "",
						"icon": "",
						"levelid": ""
					},
					"invite_num": "",
					"commission": "",
					"is_deposit": "",
					"is_account": "",
					"dengjidaoqishijian": "",
					"suozaidi": "",
					"huiyuanyue": "",
					"working_hours": "",
					"credit_score": "",
					"deposit": "",
					"deposit_switch": "",
					"withdrawal": "",
					"account_wx": "",
					"account_alipay": "",
					"account_bank": "",
					"joinin_state": "",
					"fid": "",
					"chinaarea_id": "",
					"city_status": "",
					"service_status": ""
				}
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},
			userInfo: {
				get() {
					return this.$store.state.userInfo
				},
				set() {
					this.$store.commit('updateUserInfo', value)
				},
			},
			/**
			 * @returns 
			 * Android       安卓
			 * IOS       苹果
			 * Web       H5 或 pc
			 * Wechat       微信小程序
			 * Alipay       支付宝小程序
			 * Baidu       百度小程序
			 * ByteBounce       抖音小程序
			 * 360       360小程序
			 * FastApp       快应用
			 */
			appSystemIdentification() {
				return this.$store.state.appSystemIdentification
			}
		},
		watch: {},
		onLoad(options) {
			this.getUserDataFunc()
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//裁剪图片上传
			croppingUploadImage(id, path, obj, obj1, fnName = false) {
				if (!this.setCheckPermission(2)) {
					return
				}
				let self = this
				if (!obj) obj = this
				if (!obj1) obj1 = this
				let itemList = obj1[path] ? ['修改头像', '拍照', '从手机相册选择'] : ['拍照', '从手机相册选择']

				function imageCroppingCuccess() {
					uni.$once('image-cropping-success', (file) => {
						if (!file) return
						new UploadImage([file], {
							complete: (res) => {
								if (id) self.$set(obj, id, res[0].id)
								if (path) self.$set(obj1, path, res[0].path)
								if (fnName) self[fnName]()
							},
						})
					})
				}
				uni.showActionSheet({
					itemList: itemList,
					success: function(res) {
						if (res.tapIndex == 0 && obj1[path]) {
							uni.navigateTo({
								url: '/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&&myImgUrl=' +
									obj1[path],
								animationDuration: 0,
							})
							imageCroppingCuccess()
						}
						if ((res.tapIndex == 1 && obj1[path]) || (res.tapIndex == 0 && !obj1[path])) {
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
								sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
								success: (res) => {
									// 跳转到图片裁切页面
									uni.navigateTo({
										url: `/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType=${res.tempFiles[0].type}&myImgUrl=${res.tempFilePaths[0]}`,
										animationDuration: 0,
									})
									imageCroppingCuccess()
								},
							})
						}
						if ((res.tapIndex == 2 && obj1[path]) || (res.tapIndex == 1 && !obj1[path])) {
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
								sourceType: ['album'], // 可以指定来源是相册还是相机，默认二者都有
								success: (res) => {
									// 跳转到图片裁切页面
									uni.navigateTo({
										url: `/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType=${res.tempFiles[0].type}&myImgUrl=${res.tempFilePaths[0]}`,
										animationDuration: 0,
									})
									imageCroppingCuccess()
								},
							})
						}
					},
					fail: function(res) {
						console.log(res.errMsg)
					},
				})
			},
			//获取用户信息
			async getUserDataFunc() {
				//请求方法
				//数据验证

				let datauserData = await this.$api.get(global.apiUrls.post5c78c4772da97, {
					user_id: this.userInfo.id
				});

				if (datauserData.data.code != 1) {
					this.$message.info(datauserData.data.msg);
					return
				}
				let infouserData = datauserData.data;
				this.userData = infouserData.data

			},
			//提交修改用户信息
			async postUserDataFunc() {
				if (!validate(this.userData.avatar, 'require')) {
					this.$message.info('头像不能为空');
					return false;
				}
				if (!validate(this.userData.nickname, 'require')) {
					this.$message.info('名称不能为空');
					return false;
				}
				if (!validate(this.userData.suozaidi, 'require')) {
					this.$message.info('地址不能为空');
					return false;
				}
				//请求方法
				//数据验证

				let data646b536d5b1a6 = await this.$api.post(global.apiUrls.post646b536d5b1a6, {
					nickname: this.userData.nickname,
					avatar: this.userData.avatar,
					suozaidi: this.userData.suozaidi
				});

				if (data646b536d5b1a6.data.code != 1) {
					this.$message.info(data646b536d5b1a6.data.msg);
					return
				}



				this.$message.info('修改成功');
				setTimeout(() => {
					this.$urouter.navigateBack(1);
				}, 500)
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(248, 248, 248, 1);
		background-size: 100% auto;
	}

	.means_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.means_fd0_0_c1 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
		line-height: 50rpx;
	}

	.means_fd0_0_c0_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
		line-height: 88rpx;
	}

	.means_fd0_0_c0 {
		width: 200rpx;
		height: 88rpx;
	}

	.means_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.means_flex_1 {
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		background-size: 100% auto !important;
	}

	.means_fd1_4 {
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.means_fd1_3_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.means_fd1_2_c1 {
		line-height: 110rpx;
		font-size: 32rpx;
		color: #333;
		font-weight: 500;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.means_fd1_1_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #666666;
	}

	.means_fd1_0_c1_image {
		width: 94rpx;
		height: 94rpx;
		border-radius: 47rpx 47rpx 47rpx 47rpx;
	}

	.means_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
	}

	.means_fd1_0 {
		border-bottom: 1px solid #eee;
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.means_flex_2 {
		width: 750rpx;
		height: 128rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
	}

	.means_fd2_0 {
		background: #E31D1A;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		font-size: 32rpx;
		color: #fff;
		width: 638rpx;
		height: 80rpx;
		line-height: 80rpx;
	}

	.means_picker3_0_c2 {
		color: rgba(227, 29, 26, 1);
		font-size: 32rpx;
		font-weight: 400;
		line-height: 45rpx;
	}

	.means_picker3_0_c1 {
		font-size: 36rpx;
		font-weight: 400;
		color: #333;
	}

	.means_picker3_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: rgba(153, 153, 153, 1);
	}

	.means_picker3_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		border-radius: 16rpx 16rpx 0rpx 0rpx;
		background-size: 100% auto !important;
		height: 100rpx;
	}
</style>